<template>
    <div>
        <Card>
            <!-- search start -->
            <div class="search">
                <Form :model="search" class="search_box" inline label-position="right">
                    <FormItem label="分部：">
                        <Select class="option" v-model="search.branchid">
                            <Option :value="-1">全部</Option>
                            <Option v-for="item in branchList " :value="item.value" :key="item.value">{{ item.label }}</Option>
                        </Select>
                    </FormItem>

                    <FormItem label="时间：">
                        <DatePicker style="width:300px" type="datetimerange" placeholder="Select date and time" @on-change="changeTime($event)"></DatePicker>
                    </FormItem>

                    <FormItem>
                        <Button icon="md-search" type="primary" @click="searchList">搜索</Button>
                    </FormItem>

                </Form>

            </div> <!-- end search -->

            <Table ref="table" :loading="loading" stripe :columns="columns1" :data="data1"></Table>
        </Card>

    </div>
</template>

<script>
    import axios from '@/libs/api.request'
    import {
        mapGetters,
        mapMutations
    } from 'vuex'
    export default {
        name: 'check-all',
        data() {
            return {
                loading: false,

                // 搜索对象
                search: {
                    start_time: '',
                    end_time: '',
                    branchid: -1,
                },

                columns1: [{
                        type: 'index',
                        width: 60,
                        align: 'center'
                    },

                    {
                        title: '分部',
                        align: 'center',
                        key: 'name'
                    },
                    {
                        title: '应巡店次数',
                        align: 'center',
                        key: 'must_num'
                    },
                    {
                        title: '实际巡店次数',
                        align: 'center',
                        key: 'already_num'
                    },
                    {
                        title: '未巡店次数',
                        align: 'center',
                        key: 'no_num',
                    },
                    {
                        title: '排名',
                        align: 'center',
                        key: 'rank',
                    }
                ],
                data1: []
            }
        },
        methods: {
            ...mapGetters(['getBranchList']),

            // 获取巡店统计列表
            getCheckAllList() {
                this.loading = true
                let data = this.search
                axios.ajax_post('admin-patrol_total-ajax_get_pt', data).then(res => {
                    this.loading = false
                    if (res.data.code === 1) {
                        this.data1 = res.data.data.list
                        this.total = res.data.data.total_num
                    } else {
                        this.$Notice.error({
                            title: res.data.msg,
                            duration: 3
                        })
                    }
                })

            },

            // 搜索
            searchList() {
                this.getCheckAllList()
            },

            // 格式化时间
            changeTime(value) {
                this.search.start_time = value[0]
                this.search.end_time = value[1]
            },
        },
        computed: {
            branchList() {
                return this.getBranchList()
            },
        },
        created() {
            this.getCheckAllList()
        }
    }
</script>

<style lang='less' scoped>
    .search {
        .search_box {
            display: flex;

            .option {
                width: 100px;
            }

            .ivu-form-item {
                margin-right: 12px;
                display: flex;
                justify-content: flex-start;
                margin-bottom: 20px;
            }
        }
    }
</style>